const t = require("./dict");
const { getChoicesURLs } = require("../config/download");
const cloneDeep = require("lodash/cloneDeep");
const { checkCustomLangPack } = require("../lib/utils");
const config = require("../mfo.config.js");
const dict = process.env.LANGPACK
  ? checkCustomLangPack()
  : require("../config/" + config.language.langPack);
const { stringCase } = require("../lib/utils");

const inquirerConfig = (context, ignore) => {
  return [
    {
      name: "projectName",
      message: t(context.lang, "项目名称"),
      default: `${context.name}`,
    },
    {
      name: "projectVersion",
      message: t(context.lang, "项目版本"),
      default: "1.0.0",
    },
    {
      name: "projectDescription",
      message: t(context.lang, "项目简介"),
      default: `A project named ${context.name}`,
    },
    {
      name: "projectKeywords",
      message: t(context.lang, "项目关键字"),
      default: `${context.name},`,
    },
    {
      name: "projectAppId",
      message: t(context.lang, "App ID"),
      default: "",
    },
    {
      name: "projectAuthor",
      message: t(context.lang, "项目作者"),
      default: "mfo",
    },
    {
      name: "projectDir",
      message: t(context.lang, "项目所在目录"),
      default: `${context.name}`,
    },
  ].filter((item) => (ignore ? !ignore.includes(item.name) : true));
};

const technologyStackChoices = () => {
  return getChoicesURLs()
    .then((choicesURLs) => {
      return cloneDeep(choicesURLs);
    })
    .catch((err) => Promise.reject(err));
};

const developLangChoices = [
  {
    name: "Javascript",
    value: "javascript",
  },
  {
    name: "Typescript",
    value: "typescript",
  },
];

const dirOperaTypeChoices = [
  {
    name: "覆盖",
    value: "overwrite",
  },
  {
    name: "重新命名",
    value: "rename",
  },
];

const sources = [
  {
    name: "Npm",
    value: "https://registry.npmjs.org/",
  },
  {
    name: "Taobao",
    value: "https://registry.npmmirror.com/",
  },
  {
    name: "Yarn",
    value: "https://registry.yarnpkg.com/",
  },
  {
    name: "CNpm",
    value: "http://r.cnpmjs.org/",
  },
];

const boolChoies = [
  {
    name: "是",
    value: "yes",
  },
  {
    name: "否",
    value: "no",
  },
];

const langChoies = () => {
  let langs = [];
  Object.keys(dict).forEach((n) =>
    langs.push({
      name: stringCase(n),
      value: n.toLocaleLowerCase(),
    })
  );
  return langs;
};

const clientChoices = [
  {
    name: "Web",
    value: "web",
  },
  {
    name: "Apps and applets",
    value: "apps",
  },
];

const microAppType = [
  {
    name: "主应用",
    value: "hostApp",
  },
  {
    name: "子应用",
    value: "subApp",
  },
];

module.exports = {
  langChoies,
  boolChoies,
  // LOCALSOURCE,
  technologyStackChoices,
  inquirerConfig,
  timeout: 1000 * 60 * 10,
  defaultTemplate: "No UI",
  dirOperaTypeChoices,
  developLangChoices,
  clientChoices,
  microAppType,
  sources,
};
